var macro;
var jsLF = "\n";
var i, retcode, errtext;
var MyDelay;
var MyPosts;

var Aldeias;

var espioes;
var cavalariaLeve;
var command;
var local;

local = "overview";
local = "snob";
//local = "place";
//local = "stable";
local = "barracks";
//local = "main";
//local = "place&mode=units";


var time = 10;

i = 0;

espioes = 1;
cavalariaLeve = 7;
//command = commandPega();



Aldeias = new Array();
//001
Aldeias.push("151866");
//002
Aldeias.push("148279");
//003
Aldeias.push("154188");
//004
Aldeias.push("142661");
//005
Aldeias.push("151454");
//006
Aldeias.push("143739");
//007
Aldeias.push("151479");
//008
Aldeias.push("148776");
//009
Aldeias.push("158142");
//010
Aldeias.push("155821");
//011
Aldeias.push("149294");
//012
Aldeias.push("158270");
//013
Aldeias.push("164095");
//014
Aldeias.push("160320");
//015
Aldeias.push("169566");
//016
Aldeias.push("182932");
//017
Aldeias.push("157338");
//018
Aldeias.push("167656");
//019
Aldeias.push("158179");
//020
Aldeias.push("159542");
//021
Aldeias.push("158360");
//022
Aldeias.push("164017");
//023
Aldeias.push("151099");
//024
Aldeias.push("156772");
//025
Aldeias.push("161334");
//026
Aldeias.push("156550");




MyDelay = 0;

for (i ; i < Aldeias.length; i++) {
    iimSet("POSTID", Aldeias[i]);
    
    macro = "CODE:";
    macro += "URL GOTO=http://br35.tribalwars.com.br/game.php?village={{postid}}&screen=" + local + jsLF;
    macro += "WAIT SECONDS=" + time + jsLF;
//
//    //macro += "TAG POS=1 TYPE=TD ATTR=ID:inner-border EXTRACT=HTM";
    iimPlay(macro);
//
//    var text = iimGetLastExtract();
//
//    var numCavalariaLeve = text.substr(text.indexOf("('#unit_input_light')")+23,10);
//    numCavalariaLeve = numCavalariaLeve.substr(0,numCavalariaLeve.indexOf(")"));
//    numCavalariaLeve = parseInt(numCavalariaLeve);
//    //  alert(numCavalariaLeve);
//
//    if(numCavalariaLeve<cavalariaLeve){
//        //alert("não ha cavalos suficientes. Necessário "+cavalariaLeve);
//        macro = "CODE:";
//        macro += "WAIT SECONDS=60" + jsLF;
//        iimPlay(macro);
//        i--
//        continue;
//    }
//
//    var numSpy = text.substr(text.indexOf("('#unit_input_spy')")+20,10);
//    numSpy = numSpy.substr(0,numSpy.indexOf(")"));
//    numSpy = parseInt(numSpy);
//    //    alert(numSpy);
//
//    if(numSpy<espioes){
//        //alert("não ha espioes. Necessário "+espioes);
//        macro = "CODE:";
//        macro += "WAIT SECONDS=60" + jsLF;
//        iimPlay(macro);
//        i--
//        continue;
//
//    }
//
//
//    macro = "CODE:";
//    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_spy CONTENT="+ espioes + jsLF;
//    macro += "TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:units ATTR=ID:unit_input_light CONTENT=" + cavalariaLeve + jsLF;
//    macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:units_form ATTR=ID:target_attack" + jsLF;
//    macro += "TAG POS=1 TYPE=TD ATTR=ID:inner-border EXTRACT=HTM";
//
//    iimPlay(macro);
//
//    text = iimGetLastExtract();
//    command = text.substr(text.indexOf("action=command&amp;h=")+21,4);
//
//    macro = "CODE:";
//    macro += "TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:http://br36.tribalwars.com.br/game.php?village=31611&screen=place&action=command&h="+ command +" ATTR=ID:troop_confirm_go" + jsLF;
//    macro += "WAIT SECONDS=" + MyDelay + jsLF;
//
//
//    iimDisplay("Executando "+i);
//
//    retcode = iimPlay(macro);
//    if (retcode < 0) {              // an error has occured
//        errtext = iimGetLastError();
//        alert(errtext);
//        i--;
//
//    //commandPega();
//
//    // break;
//    }
}
